home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 2000 November: Tool Chest / Dev.CD Nov 00 TC Disk 2.toast / pc / sample code / platforms and tools / project builder / simplecocoaapp / hellocontroller.m < prev    next >
Encoding:
Text File  |  2000-10-10  |  5.6 KB  |  110 lines

  1. /*
  2. File:        HelloController.m
  3.  
  4. Description:     This is the implementation file for the class that handles the interaction between the GUI
  5.                 and the Hello objects, allowing you to switch messages and receiver objects.  Calling Help
  6.                 Viewer to display our help file is also handled here.
  7.  
  8. Author:        MCF
  9.  
  10. Copyright:     © Copyright 2000 Apple Computer, Inc. All rights reserved.
  11.  
  12. Disclaimer:    IMPORTANT:  This Apple software is supplied to you by Apple Computer, Inc.
  13.                 ("Apple") in consideration of your agreement to the following terms, and your
  14.                 use, installation, modification or redistribution of this Apple software
  15.                 constitutes acceptance of these terms.  If you do not agree with these terms,
  16.                 please do not use, install, modify or redistribute this Apple software.
  17.  
  18.                 In consideration of your agreement to abide by the following terms, and subject
  19.                 to these terms, Apple grants you a personal, non-exclusive license, under Apple’s
  20.                 copyrights in this original Apple software (the "Apple Software"), to use,
  21.                 reproduce, modify and redistribute the Apple Software, with or without
  22.                 modifications, in source and/or binary forms; provided that if you redistribute
  23.                 the Apple Software in its entirety and without modifications, you must retain
  24.                 this notice and the following text and disclaimers in all such redistributions of
  25.                 the Apple Software.  Neither the name, trademarks, service marks or logos of
  26.                 Apple Computer, Inc. may be used to endorse or promote products derived from the
  27.                 Apple Software without specific prior written permission from Apple.  Except as
  28.                 expressly stated in this notice, no other rights or licenses, express or implied,
  29.                 are granted by Apple herein, including but not limited to any patent rights that
  30.                 may be infringed by your derivative works or by other works in which the Apple
  31.                 Software may be incorporated.
  32.  
  33.                 The Apple Software is provided by Apple on an "AS IS" basis.  APPLE MAKES NO
  34.                 WARRANTIES, EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION THE IMPLIED
  35.                 WARRANTIES OF NON-INFRINGEMENT, MERCHANTABILITY AND FITNESS FOR A PARTICULAR
  36.                 PURPOSE, REGARDING THE APPLE SOFTWARE OR ITS USE AND OPERATION ALONE OR IN
  37.                 COMBINATION WITH YOUR PRODUCTS.
  38.  
  39.                 IN NO EVENT SHALL APPLE BE LIABLE FOR ANY SPECIAL, INDIRECT, INCIDENTAL OR
  40.                 CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
  41.                 GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
  42.                 ARISING IN ANY WAY OUT OF THE USE, REPRODUCTION, MODIFICATION AND/OR DISTRIBUTION
  43.                 OF THE APPLE SOFTWARE, HOWEVER CAUSED AND WHETHER UNDER THEORY OF CONTRACT, TORT
  44.                 (INCLUDING NEGLIGENCE), STRICT LIABILITY OR OTHERWISE, EVEN IF APPLE HAS BEEN
  45.                 ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  46.                 
  47. Change History (most recent first):
  48.  
  49. 09/2000 - MCF - initial version
  50.  
  51. */
  52.  
  53. //we use #import to make sure the header is only read in once
  54. #import "HelloController.h"
  55.  
  56. @implementation HelloController
  57.  
  58. //This method is called when the user picks a different message 
  59. //to display by clicking a different radio button
  60. - (IBAction)switchMessage:(id)sender
  61. {
  62.         //sender is the NSMatrix containing the radio buttons.
  63.         //We ask the sender for which row (radio button) is selected and add one
  64.         //to compensate for counting from zero.
  65.         int which=[sender selectedRow]+1;
  66.         //We now set our NSButton's action to be the message corresponding to the radio button selection.
  67.         //+[NSString stringWithFormat:...] is used to concatenate "message" and the message number.  
  68.         //NSSelectorFromString converts the message name string to an actual message structure that
  69.         //Objective-C can use.
  70.         [helloButton setAction:NSSelectorFromString([NSString stringWithFormat:@"%@%d:",@"message",which])];        
  71. }
  72.  
  73. //This method is called when the user picks a different object to 
  74. //receive messages using the PopUp menu
  75. - (IBAction)switchObject:(id)sender
  76. {
  77.         //sender is the NSPopUpMenu containing Hello object choices.
  78.         //We ask the sender for which menu item is selected and add one
  79.         //to compensate for counting from zero.
  80.         int which=[sender indexOfSelectedItem]+1;
  81.         
  82.         //Based on which menu item is selected, we set the target (the receiving object)
  83.         //of the helloButton to point to either hello1 or hello2.
  84.         if (which==1)
  85.         [helloButton setTarget:hello1];
  86.         else
  87.         [helloButton setTarget:hello2];
  88. }
  89.  
  90. //awakeFromNib is called when this object is done being unpacked from the nib file;
  91. //at this point, we can do any needed initialization before turning app control over to the user
  92. - (void)awakeFromNib
  93. {
  94.     //Bring the window to the front and make it the receiving window for key events
  95.     [[helloButton window] makeKeyAndOrderFront:self];
  96. }
  97.  
  98. //This method is called when the user selects "HelloCocoa Help" from the Help menu
  99. - (IBAction)showHelp:(id)sender
  100. {
  101.     //We call -[NSWorkspace openFile:withApplication:] to open our html file with the Help Viewer,
  102.     //using -[NSBundle pathForResource:ofType:] to help us find our html file
  103.     NSString *path = [[NSBundle mainBundle] pathForResource:@"ReadMe" ofType:@"html"];
  104.     if (path) {
  105.         [[NSWorkspace sharedWorkspace] openFile:path withApplication:@"Help Viewer"];
  106.     }
  107. }
  108.  
  109. @end
  110.